package com.situ.user.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.situ.user.bean.OrderDetails;

public interface OrderDetailsMapper {
	@Delete({ "delete from order_details", "where id = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into order_details ( goods_id, ", "order_id, price, ", "count)",
			"values ( #{goodsId,jdbcType=INTEGER}, ", "#{orderId,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, ",
			"#{count,jdbcType=INTEGER})" })
	int insert(OrderDetails record);

	@Select({ "select", "id, goods_id, order_id, price, count", "from order_details",
			"where id = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "goods_id", property = "goodsId", jdbcType = JdbcType.INTEGER),
			@Result(column = "order_id", property = "orderId", jdbcType = JdbcType.VARCHAR),
			@Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL),
			@Result(column = "count", property = "count", jdbcType = JdbcType.INTEGER) })
	OrderDetails selectByPrimaryKey(Integer id);

	@Select({ "select", "id, goods_id, order_id, price, count", "from order_details" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "goods_id", property = "goodsId", jdbcType = JdbcType.INTEGER),
			@Result(column = "order_id", property = "orderId", jdbcType = JdbcType.VARCHAR),
			@Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL),
			@Result(column = "count", property = "count", jdbcType = JdbcType.INTEGER) })
	List<OrderDetails> selectAll();

	@Update({ "update order_details", "set goods_id = #{goodsId,jdbcType=INTEGER},",
			"order_id = #{orderId,jdbcType=VARCHAR},", "price = #{price,jdbcType=DECIMAL},",
			"count = #{count,jdbcType=INTEGER}", "where id = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(OrderDetails record);

	@Select("select * from order_details where order_id=#{orderId}")
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "goods_id", property = "goodsId", jdbcType = JdbcType.INTEGER),
			@Result(column = "order_id", property = "orderId", jdbcType = JdbcType.VARCHAR),
			@Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL),
			@Result(column = "count", property = "count", jdbcType = JdbcType.INTEGER),
			@Result(column = "goods_id", property = "goods", one = @One(select = "com.situ.user.mapper.GoodsMapper.selectByPrimaryKey")) })

	List<OrderDetails> selectByOrderId(String orderId);
}